package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.log.LogAnno;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.QueryPageBean;
import com.itheima.pojo.Result;
import com.itheima.service.LogService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/log")
public class LogController {
    @Reference
    LogService logService;


    @LogAnno("查询分页日志")
    @RequestMapping("/findPage")
    @PreAuthorize("hasAnyAuthority('LOG_QUERY')")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        return logService.findPage(queryPageBean);
    }

    @LogAnno("删除日志")
    @RequestMapping("/deleteById")
    @PreAuthorize("hasAnyAuthority('LOG_DELETE')")
    public Result deleteById(int id) {
        try {
            logService.deleteById(id);
            return new Result(true, "删除日志成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "删除日志失败");
        }
    }
}
